package com.meeting.y.util;

import com.jfinal.plugin.activerecord.Record;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.util.List;

public class ExcelUtil {

    //判断文件是否存在
    public static boolean fileExist(String filePath){
        boolean flag = false;
        File file = new File(filePath);
        flag = file.exists();
        return flag;
    }

    //向Excel中写数据
    public static void writeExcel(XSSFSheet sheet,List<Record> list ,int beginrow,int begincell,String [] keysort) {
        int addrow = 0;
        for(Record record:list){
            int addcell = 0;
            XSSFRow Row = sheet.getRow(beginrow+addrow);
            if(Row == null){
                Row = sheet.createRow(beginrow+addrow);
            }
            for(String key:keysort){
                XSSFCell cell = Row.getCell(begincell+addcell);
                if(cell == null){
                    cell = Row.createCell(begincell+addcell);
                }
                cell.setCellValue(record.getStr(key));
                addcell++;
            }
            addrow++;
        }

    }

}
